﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAO
{
    public class DogDao: BaseDao
    {
        public Dog Dog { get; set; }

        public List<Dog> GetAllDog()
        {
            var query = from c in _agiltasticDbEntities.Dog.Include("Breed1").Include("Category1").Include("Degree1").Include("Handler1")
                        orderby c.Name
                        select c;
            return query.ToList();
        }

        public Dog GetById(int id)
        {
            var query = from c in _agiltasticDbEntities.Dog
                        where c.Id == id
                        select c;
            return query.FirstOrDefault();
        }

        public void Update(Dog currentSelected)
        {
            var Dog = GetById(currentSelected.Id);
            Dog.Name = currentSelected.Name;
            
            Dog.CategoryName = currentSelected.CategoryName;
            Dog.Category = currentSelected.Category;
            Dog.DegreeName = currentSelected.DegreeName;
            Dog.Degree = currentSelected.Degree;
            Dog.BreedName = currentSelected.BreedName;
            Dog.Breed = currentSelected.Breed;
            Dog.HandlerName = currentSelected.HandlerName;
            Dog.Handler= currentSelected.Handler;
            _agiltasticDbEntities.SaveChanges();
        }

        public void Save(Dog currentSelected)
        {
            _agiltasticDbEntities.Dog.Add(currentSelected);
            _agiltasticDbEntities.SaveChanges();
        }
    }
}
